app.controller('indexController', function($scope, $controller, baseService){
    // 继承基础控制器
    $controller('baseController',{$scope:$scope});

    /* 1.显示登录名*/
    $scope.showLoginName=function (){
        baseService.sendGet("/admin/getLoginName").then(function (response) {
            $scope.loginName=  response.data;
            console.log($scope.loginName)
        })
    }

    // 2.检查两次密码是否一致
    $scope.check=function () {
         if(!angular.equals($scope.newps,$scope.agnewps)){
             alert("两次密码不一致，重新输入");
             $scope.agnewps="";
             $scope.newps=""

             return false;
         }
         return true;
    }

    // 3.修改密码
    $scope.updatePassword=function () {
        if($scope.old!=undefined&&$scope.agnewps!=undefined&&$scope.newps!=undefined){
            if( $scope.check()){
                baseService.sendPost("/admin/findPassword?old="+$scope.old).then(function (response) {
                    if(response.data){
                        baseService.sendPost("/admin/update?newps="+ $scope.newps).then(function (value) {
                            if (value.data) {
                                alert("修改成功")
                                $scope.agnewps="";
                                $scope.newps="";
                                $scope.old="";
                            }else {
                                alert("修改失败")
                            }
                        })
                    }else {
                        alert("原密码不正确，重新输入");
                        $scope.old="";
                    }
                })
            }

        }else {
            alert("密码不能为空")
        }
    }

})